package com.qianxun.framework.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: huwei
 * @date: 2019/9/18 15:42
 * @version: 1.0.0
 */
public class ErrorUtil {

    /**
     * 获取指定异常的堆栈信息
     * @param throwable 异常
     * @return
     */
    public static String getStackTrace(Throwable throwable){
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        PrintWriter printWriter = new PrintWriter(byteArrayOutputStream);
        throwable.printStackTrace(printWriter);
        printWriter.flush();
        String res = byteArrayOutputStream.toString();
        printWriter.close();
        try {
            byteArrayOutputStream.close();
        } catch (IOException e) {
        }
        return res;
    }
}
